#coding: utf-8
#!/usr/bin/python
import datetime
import unittest
from  TextFilter import *

class TextFilterTest(unittest.TestCase):

	def setUp(self):
		self.pubDate = datetime.date(2012,1,1)
		self.textFilter = TextFilter(pubDate)

	def testInit(self):
		assert self.textFilter is not None

	def testMecabSpliter(self):	
		# prepare
		text = "太郎はこの本を二郎を見た女性に渡した。"

		result = self.textFilter.mecabSpliter(text)
		
		# assert
		expected = ["太郎", "本","二","郎","女性"]
		self.assertEqual(result, expected)

	def testTermFreq(self):
		# prepare
		text = "太郎はこの本を太郎を見た女性に渡した。"
		self.textFilter.mecabSpliter(text)

		# assert
		result = self.textFilter.termFreq("太郎")
		expected = 2
		self.assertEqual(result, expected)
	
	def testTextToVec(self):
		# prepare
		text = "太郎はこの本を太郎を見た女性に渡した。"

		result = self.textFilter.textToVec(text)
		expected = {'太郎':2,'本':1,'女性':1}
		# debug
		'''
		for term, cnt in result.iteritems():
			print term, '\t', cnt
		'''
		# assert
		self.assertEqual(result, expected)

	def testGetPubDate(self):
		# assert
		expected = datetime.date(2012,1,1)
		result = self.textFilter.getPubDate()
		self.assertEqual(result, expected)


	def testWeightOfDoc(self):
		# prepare
		ramda = 0.5
		currentDate = datetime.date.today()
		diff = currentDate - self.pubDate

		# assert
		expected = ramda ** (diff.days)
		result = self.textFilter.weightOfDoc(ramda)
		self.assertEqual(result, expected)
		


if __name__ == '__main__':
	unittest.main()
